package com.ea.modular.controller.sys;


import java.text.SimpleDateFormat;
import java.util.Date;


import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import org.springframework.ui.Model;

import com.ea.common.annotation.LogAnnotation;
import com.ea.common.parent.controller.BaseController;
import com.ea.modular.model.sys.Log;
import com.ea.modular.service.sys.LogService;

import io.swagger.annotations.ApiOperation;




/**
 * 日志管理的控制器
 *
 * @author jun
 */
@Controller
@RequestMapping("/log")
public class LogController extends BaseController {

    private static String PREFIX = "/system/log/";


    @Autowired
    private LogService logService;

    /**
     * 跳转到日志管理的首页
     */
    @RequestMapping("")
    @RequiresPermissions("sys:log:view")
    public String index(Model model) {
    	SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");//设置查询时间
    	model.addAttribute("beginTime",df.format(new Date()));
        return PREFIX + "log";
    }

    /**
     * 查询操作日志列表
     */
	@ApiOperation(value = "日志列表")
    @RequestMapping(value = "/list",method=RequestMethod.POST)
    @ResponseBody
    public Object list(@RequestParam(required = false) String beginTime, @RequestParam(required = false) String endTime, @RequestParam(required = false) String logName, @RequestParam(required = false) String logType) {

    	Log log = new Log();        
    	log.setBeginTime(beginTime);
    	log.setOverTime(endTime);
    	log.setTitle(logName);
    	log.setOpsType(logType);
    	
    	return logService.findPage(log);
    	
    }
	
	
	/**
	 * 清空日志
	 * @return
	 */
	@LogAnnotation
	@ApiOperation(value = "清空日志")
	@RequestMapping(value = "/removeall",method=RequestMethod.POST)
	@ResponseBody
	public int removeall() {
		return logService.removeall();
	}
	
	  /**
     * 查询操作日志详情
     */
    @RequestMapping("/detail/{id}")
    public String detail(@PathVariable String id,Model model) {
      Log log = logService.get(id);	
      model.addAttribute("log",log);
      return PREFIX + "log_detail";
    }
}
